﻿using System;
using System.Diagnostics;
using System.Collections.Generic;
//using System.Linq;
//using System.Text;
using System.Xml;
using System.Drawing;
namespace LedCenter.Models
{
    public interface IBaseProgram
    {
        string ToXML();
        Bitmap CreateBitmapImage();

    }

    public enum PROGRAM_TYPE
    {
        TEXT,
        IMAGE,
        CLOCK,
        PLAYLIST,
        UNKNOW
    }

    public abstract class BaseProgram : IBaseProgram
    {

        // Program name
        public ushort ID { get; set; }
        // Program type
        public PROGRAM_TYPE Type { get; set; }

        /* 
         * Constructors 
        **/
        /// <summary>
        /// Default Constructor
        /// </summary>
        /// <returns></returns>
        public BaseProgram()
        {
            ID = 0;
            Type = PROGRAM_TYPE.UNKNOW;
        }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="name">Device's name</param>
        /// <param name="type">Device's type</param>
        public BaseProgram(ushort id, PROGRAM_TYPE type)
        {
            ID = id;
            Type = type;
        }

        /// <summary>
        /// return xml string as:
        /// <Program Name="Program text" Type="text">
        ///     
        /// </Program>
        /// </summary>
        /// <returns></returns>
        public virtual string ToXML()
        {
            string xmlContent = "<Program></Program>";
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(xmlContent);
            XmlNode newNode = doc.DocumentElement;
            XmlAttribute nameAttribute = doc.CreateAttribute("Name");
            nameAttribute.Value = ID.ToString();
            newNode.Attributes.Append(nameAttribute);

            XmlAttribute typeAttribute = doc.CreateAttribute("Type");
            typeAttribute.Value = Enum.GetName(typeof(PROGRAM_TYPE),Type);
            newNode.Attributes.Append(typeAttribute);

            Debug.WriteLine(newNode.OuterXml);
            return newNode.OuterXml;
        }

        /// <summary>
        /// Generate bitmap image for program
        /// by default, base program image is solid color
        /// </summary>
        /// <returns></returns>
        public virtual Bitmap CreateBitmapImage()
        {
            Bitmap curImage = new Bitmap(128, 64);
            using (Graphics g = Graphics.FromImage(curImage))
            {
                g.FillRectangle(Brushes.MediumSpringGreen, 0f, 0f, (float)curImage.Width, (float)curImage.Height);
            }
            return curImage;
        }
    }
}
